package com.cjet.nissan.room

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query

@Dao
interface AppDatabaseDao {

    @Insert
    fun insert(night: NTDS)

    @Query(("SELECT * from user_collect_table WHERE id = :key"))
    fun get(key: Long): NTDS?



    @Query("DELETE FROM user_collect_table")
    fun clear()


//    var type: Int = 0, // 0 Heart Rate  1 Respiratory Rate  2Emotional State

    // 获取当天的数据
    @Query("SELECT * FROM user_collect_table where  type = 0 and time = :time  ORDER BY time DESC")
    fun getAllHeartRate(time: Long): LiveData<List<NTDS>>

    // 获取当天的数据
    @Query("SELECT * FROM user_collect_table where  type = 1 and time = :time  ORDER BY time DESC")
    fun getAllRespiratoryRate(time: Long): LiveData<List<NTDS>>

    // 获取当天的数据 Emotional State
    @Query("SELECT * FROM user_collect_table where  type = 2 and time = :time  ORDER BY time DESC")
    fun getAllEmotionalState(time: Long): LiveData<List<NTDS>>


    // 定期清理超过30天的数据
    @Query("DELETE FROM user_collect_table where time < :time " )
    fun deleteMore30Day(time: Long)




}